Systems and methods for traffic shaping

ABSTRACT

A system shapes traffic in a multiport network device. The system includes multiple token buckets and token bucket logic. The token buckets correspond to multiple priority queues of the multiple output ports of the network device and store one or more tokens. Each of the tokens corresponds to a byte of one or more received packets to be transmitted by the network device. The token bucket control logic generates the tokens for the token buckets. The token bucket control logic includes a master counter and multiple bucket counters. The master counter counts to a first count value and generates a done signal when the count reaches the first count value. The bucket counters, corresponding to the token buckets, receive the done signal, count to a second count value, and generate a token increment signal for storing a token in the corresponding token buckets when the count reaches the second count value.

TECHNICAL FIELD

The present invention relates generally to communication systems and methods and, more particularly, to systems and methods for traffic shaping.

BACKGROUND ART

In computer networks, a number of network stations are typically interconnected via a communications medium. For example, Ethernet 802.3 is a commonly used local area network (LAN) scheme in which multiple stations are connected to a shared or dedicated serial data path. These stations often communicate with a switch or some other network device located between the data path and the stations connected to that path. The switch typically controls the communication of packets and includes logic for receiving and forwarding packets to their appropriate destinations.

A common problem in conventional network switches is how to control the traffic (e.g., the volume or rate of packets) transmitted from the switches. Traffic may be controlled to obtain some quality of service goal, such as minimizing packet loss or congestion. Some switches may use traffic shaping techniques to control traffic. “Traffic shaping” is forcing the traffic to conform to a certain specified behavior. For example, a switch might delay some packets slightly in order to reduce the peak rate and rate variance without affecting throughput.

Conventional traffic shaping techniques, however, do not permit the traffic to be controlled or fine tuned on a priority level basis for each port of a network switch.

DISCLOSURE OF THE INVENTION

There exists a need for systems and methods that fine tune traffic shaping on a per port and per priority queue basis. The systems and methods provide a token bucket mechanism that controls the traffic transmitted by a network switch. This and other needs are met by the present invention, where the packet rate or volume of packets through the network switch may be controlled, thereby facilitating the provisioning of quality of service.

Additional advantages and other features of the invention will be set forth in part in the description that follows and in part will become apparent to those having ordinary skill in the art upon examination of the following or may be learned from the practice of the invention. The advantages and features of the invention may be realized and obtained as particularly pointed out in the appended claims.

According to the present invention, the foregoing and other advantages are achieved in part by a system that controls traffic in a multiport network device. The system includes multiple token buckets and token bucket logic. The token buckets correspond to multiple priority queues which are associated with each output port of the network device and store one or more tokens. Each of the tokens corresponds to a byte of one or more received packets to be transmitted by the network device. The token bucket control logic generates the tokens for the token buckets. The token bucket control logic includes a master counter and multiple bucket counters. The master counter counts to a first count value and generates a done signal when the count reaches the first count value. The bucket counters, corresponding to the token buckets, receive the done signal, count to a second count value, and generate a token increment signal for storing a token in the corresponding token buckets when the count reaches the second count value.

In a further implementation consistent with the present invention, a method controls traffic in a network device. The method includes counting to a first count value at a first count rate; outputting a done signal when the first count value is reached; counting to a second count value at a second count rate in response to the done signal; generating a token increment signal when the second count value is reached; storing a token in a token bucket in response to the token increment signal, the token bucket corresponding to a priority queue of an output port of the network device; and determining whether to accept a packet received by the network device based on a number of tokens stored in the token bucket.

In another implementation consistent with the present invention, a multiport network device includes a receiver, a transmitter, and token bucket logic. The receiver is configured to receive multiple packets. The transmitter is configured to transmit at least some of the received packets and includes multiple output ports. The token bucket logic is configured to perform traffic shaping for the network device. The token bucket logic includes multiple token buckets and token bucket logic. The token buckets correspond to multiple priority levels of each of the output ports and store one or more tokens. Each of the tokens corresponds to a byte of one or more of the received packets. The token bucket control logic generates the tokens for the token buckets.

The token bucket control logic includes a master counter and multiple bucket counters. The master counter counts to a first count value and generates a done signal when the count reaches the first count value. The bucket counters, corresponding to the token buckets, receive the done signal, count to a second count value, and generate a token increment signal for storing a token in the corresponding token buckets when the count reaches the second count value.

Other advantages and features of the present invention will become readily apparent to those skilled in this art from the following detailed description. The embodiments shown and described provide illustration of the best mode contemplated for carrying out the invention. The invention is capable of modifications in various obvious respects, all without departing from the invention. Accordingly, the drawings are to be regarded as illustrative in nature, and not as restrictive.

BRIEF DESCRIPTION OF THE DRAWINGS

Reference is made to the attached drawings, where elements having the same reference number designation represent like elements throughout.

FIG. 1 is a block diagram of an exemplary system in which systems and methods consistent with the present invention may be implemented;

FIG. 2 is a detailed diagram of a multiport switch of FIG. 1 according to an implementation consistent with the present invention;

FIG. 3 is a diagram of the token bucket logic of FIG. 2 according to an implementation consistent with the present invention;

FIG. 4 is a diagram of the token bucket control logic of FIG. 3 according to an implementation consistent with the present invention;

FIG. 5 is an exemplary timing diagram of the operation of the token bucket control logic of FIG. 4; and

FIG. 6 is a flowchart of exemplary processing for shaping traffic of the multiport switch of FIG. 2 according to an implementation consistent with the present invention.

BEST MODE FOR CARRYING OUT THE INVENTION

The present invention will be described with the example of a switch in a packet switched network, such as an Ethernet (IEEE 802.3) network. It will become apparent, however, that the present invention is also applicable to other packet switched systems, as described in detail below, as well as to other types of systems in general.

Switch Architecture Overview

FIG. 1 is a block diagram of an exemplary system in which systems and methods consistent with the present invention may be implemented. The exemplary system may include a packet switched network 100, such as an Ethernet (IEEE 802.3) network. The packet switched network 100 may include network stations 110, transformers 120, transceivers 130 and 140, a network node 150, a host 160, external memories 170, and multiport switches 180. The network stations 110 may include conventional communication devices, such as computers, with different configurations. For example, the devices may send and receive data at network data rates of 10 megabits per second (Mb/s) or 100 Mb/s.

Each 10/100 Mb/s network station 110 may send and receive data to and from a multiport switch 180 according to either a half-duplex or fill duplex Ethernet protocol. The Ethernet protocol ISO/IEC 8802-3 (ANSI/IEEE Std. 802.3, 1993 Ed.) defines a half-duplex media access mechanism that permits all stations 110 to access the network channel with equality. Traffic in a half-duplex environment may not be distinguished over the transmission medium. Rather, each half-duplex station 110 may include an Ethernet interface card that uses carrier-sense multiple access with collision detection (CSMA/CD) to listen for traffic on the transmission medium. The absence of network traffic is detected by sensing deassertion of a receive carrier on the transmission medium.

Any station 110 having data to send may attempt to access the channel by waiting a predetermined amount of time, known as the interpacket gap interval (IPG), after deassertion of the receive carrier on the transmission medium. If multiple stations 110 are connected to the same link, each of the stations 110 may attempt to transmit data in response to the sensed deassertion of the receive carrier and after the IPG interval, possibly resulting in a collision. Hence, the transmitting station 110 may monitor the transmission medium to determine if there has been a collision due to another station 110 sending data on the same link at the same time. If a collision is detected, both stations 110 cease transmitting, wait a random amount of time, and then retry the transmission.

The 10/100 Mb/s network stations 110 that operate in full duplex mode may send and receive data packets according to the Ethernet standard IEEE 802.3u. The full duplex environment provides a two-way, point-to-point communication link enabling simultaneous transmission and reception of data packets between each link partner (i.e., the 10/100 Mb/s network station 110 and the corresponding multiport switch 180).

The transformers 120 may include magnetic transformers that provide AC coupling between the network stations 110 and the transceivers 130. The transceivers 130 may include 10/100 Mb/s physical layer transceivers that communicate with the multiport switches 180 via respective serial media independent interfaces (SMIIs) or reduced media independent interfaces (RMIIs). Each of the transceivers 130 may be configured to send and receive data packets between the multiport switch 180 and up to four network stations 110 via the SMII/RMII. The SMII/RMII may operate at a data rate sufficient to enable simultaneous transmission and reception of data packets by each of the network stations 110 and the corresponding transceiver 130.

The transceiver 140 may include one or more 1000 Mb/s (i.e., 1 Gb/s) physical layer transceivers that provide communication with nodes, such as the network node 150, via, for example, a high speed network transmission medium. The network node 150 may include one or more 1 Gb/s network nodes that send and receive data packets at a network speed of 1 Gb/s. The network node 150 may include, for example, a server or a gateway to a high-speed backbone network.

The host 160 may include a computer device that provides external management functions to control the overall operation of the multiport switches 180. The external memories 170 may include synchronous static random access memories (SSRAMs) that provide external storage for the multiport switches 180. Each of the external memories 170 may include a Joint Electron Device Engineering Council (JEDEC) pipelined burst or Zero Bus Turnaround (ZBT) SSRAM having a 64-bit wide data path and a 17-bit wide address path. The external memories 170 may be addressable as upper and lower banks of 128K in 64-bit words. The size of the external memories 170 is preferably at least 1 Mbyte with data transfers possible on every clock cycle through pipelining.

The multiport switches 180 selectively forward data packets received from the network stations 110 or the network node 150 to the appropriate destination according to the appropriate transmission protocol, such as the Ethernet protocol. The multiport switches 180 may be cascaded together (via lines 190) to expand the capabilities of the multiport switches 180.

FIG. 2 is a detailed diagram of the multiport switch 180 according to an implementation consistent with the present invention. The multiport switch 180 may include a receiver 205, a transmitter 210, a data bus 215, a scheduler 220, flow control logic 225, buffer management logic 230, a port vector queue (PVQ) 235, token bucket logic 238, output control queues 240, an internal rules checker (IRC) 245, registers 250, management information base (MIB) counters 255, a host interface 260, an external memory interface 265, an EEPROM interface 270, an LED interface 275, and a Joint Test Action Group (JTAG) interface 280.

The receiver 205 may include media access control (MAC) modules and receive buffers, such as first-in, first-out (FIFO) buffers. The receive modules may include input ports that support SMIIs, RMIIs, gigabit media independent interfaces (GMIIs), ten bit interfaces (TBIs), and proprietary interfaces for expansion with other multiport switches 180 (FIG. 1). The expansion ports (EPs) may be used to transfer data between other multiport switches 180 according to a prescribed protocol. The expansion ports may permit the multiport switches 180 to be cascaded together to form a backbone network. Each of the receive modules may include queuing logic that receives data packets from the network stations 110 and/or network node 150 and stores the packets in the corresponding receive FIFOs. The queuing logic may then send portions of the packets to the IRC 245 for processing and to the external memory 170 for storage via the external memory interface 265. The receiver 205 may also include logic for counting or otherwise determining the number of bytes included in received packets.

The transmitter 210 may include MAC modules and transmit buffers, such as FIFO buffers. The transmit modules may include output ports that support SMIIs, GMIIs, TBIs, and proprietary interfaces for expansion with other multiport switches 180. Each of the transmit modules may include dequeuing logic that obtains packets from the external memory 170 and stores the packets in the corresponding transmit FIFOs. The transmit modules may read the data packets from the corresponding transmit FIFOs and transmit the packets to the network stations 110 and/or network node 150. In an alternative implementation consistent with the present invention, the functions of the receiver 205 and transmitter 210 may be performed by a transceiver that manages both the receiving and transmitting of data packets.

The data bus 215 may include one or more conductors that connect the receiver 205, the transmitter 210, the IRC 245, and the external memory interface 265. The scheduler 220 may include logic that controls access to the external memory 170 by the queuing and dequeuing logic of the receiver 205 and transmitter 210, respectively. The multiport switch 180 is configured to operate as a non-blocking switch, where network data is received and transmitted from the switch ports at the respective wire rates of 10, 100, or 1000 Mb/s. Hence, the scheduler 220 may control the access by different ports to optimize use of the bandwidth of the external memory 170.

The flow control logic 225 may include logic that operates in conjunction with the buffer management logic 230, the PVQ 235, and the output control queues 240 to control the transmission of packets by the transmitter 210. The flow control logic 225 may control the transmitter 210 so that the transmitter 210 outputs packets in an efficient manner based on the volume of data traffic. The buffer management logic 230 may include logic that oversees the use of memory within the multiport switch 180. For example, the buffer management logic 230 may manage the use of frame pointers and the reuse of frame pointers once the data packet has been transmitted to its designated output port(s). Frame pointers identify the location of data frames stored in the external memory 170 that require transmission.

The PVQ 235 may include logic that obtains a frame pointer to the appropriate output queue(s) in output control queues 240 that correspond to the output ports to receive the data frame transmission. For multicopy frames, the PVQ 235 may supply multiple copies of the same frame pointer to more than one output queue.

The token bucket logic 238 may include logic that performs traffic shaping on a per output port and per priority queue basis, where there are multiple priority queues per output port. As described in more detail below, the token bucket logic 238 controls the acceptance of frame pointers corresponding to received data frames into the output queues of the output control queues 240.

The output control queues 240 may include a FIFO-type output queue corresponding to each of the transmit modules in the transmitter 210. Each of the output queues may include multiple priority queues for frames having different levels of priority. For example, a high priority queue may be used for frames that require a lower access latency (e.g., frames for multimedia applications or management frames). The frame pointers stored in the FIFO-type output queues may be processed by the dequeuing logic for the respective transmit modules. The dequeuing logic uses the frame pointers to access the external memory 170 to read data frames at the memory locations specified by the frame pointers.

The IRC 245 may include an internal decision making engine that makes frame forwarding decisions for data packets that are received by the receiver 205. The IRC 245 may monitor (i.e., “snoop”) the data bus 215 to determine the frame pointer value and a part of the data frame, for example, the header information of a received packet, including the source, destination, and virtual local area network (VLAN) address information. The IRC 245 may use the header information to determine which output port will output the data frame stored at the location specified by the frame pointer. The IRC 245 may, thus, determine that a given data frame should be output by either a single port (i.e., unicast), multiple ports (i.e., multicast), all ports (i.e., broadcast), or no port (i.e., discarded).

For example, each data frame may include a header that identifies the source and destination addresses. The IRC 245 may use the destination address to identify the appropriate output port to output the data frame. The frame header may also include VLAN address information that identifies the frame as information destined to one or more members of a group of network stations 110. The IRC 245 may alternatively determine that a data frame should be transferred to another multiport switch 180 via the expansion port. Therefore, the IRC 245 determines whether a frame temporarily stored in the external memory 170 should be output to a single output port, multiple output ports, no output port, or another multiport switch 180.

The IRC 245 may output its forwarding decision to the PVQ 235 in the form of a forwarding descriptor. The forwarding descriptor may include, for example, a priority class identifying whether the data frame is high priority or low priority, a port vector identifying each output port that should transmit the frame, the input port number, or VLAN information. The PVQ 235 may decode the forwarding descriptor to obtain the frame pointer. The PVQ 235 may then supply the frame pointer to the appropriate output queues within the output control queues 240.

The IRC 245 may also perform layer 3 filtering. For example, the IRC 245 may examine each received data packet for up to 128 programmable patterns and process the packet based on the result. The result may dictate that the IRC 245 drop the packet, forward the packet to the host 160, or assign a user priority or a Differentiated Services Code Point (DSCP) to the packet. User priorities and the DSCP may be independently mapped into output priority classes.

The registers 250 may include configuration and status registers used by the host interface 260. The MIB counters 255 may provide statistical network information in the form of MIB objects for use by the host 160. The host interface 260 may include a standard interface that permits an external management entity, such as the host 160, to control the overall operation of the multiport switch 180. The host interface 260 may decode host accesses within a prescribed register space and read and write configuration and status information to and from the registers 250.

The external memory interface 265 may include a standard interface that permits access to the external memory 170. The external memory interface 265 may permit external storage of packet data in the external memory 170 in a direct memory access (DMA) transaction during an assigned time slot determined by the scheduler 220. In an implementation consistent with the present invention, the external memory interface 265 operates at a clock frequency of at least 66 MHz and, preferably, at a frequency of 100 MHz or above.

The EEPROM interface 270 may include a standard interface to another external memory, such as an EEPROM. The LED interface 275 may include a standard interface to external LED logic. The LED interface 275 may send the status of conditions of the input and output ports to the external LED logic. The LED logic may drive LED display elements that are human-readable. The JTAG interface 280 may include a standard interface to external testing equipment to permit, for example, a boundary scan test to be performed on the multiport switch 180.

The foregoing description of the switch architecture provides an overview of the switch operations in a packet switched network. A more detailed description of the features of the present invention as embodied, for example, in the multiport switch 180 is provided below.

Exemplary Token Bucket Logic

The present invention is directed to logic that permits the switch 180 traffic to be controlled on a per priority, per port basis, increasing the efficiency of the switch and facilitating the provisioning of quality of service.

FIG. 3 is a diagram of the token bucket logic 238 according to an implementation consistent with the present invention. The token bucket logic 238 may include multiple token buckets 310 and token bucket control logic 320. The token buckets 310 may store tokens that correspond to bytes of packets received by the switch 180 to be transmitted from the output ports. When a token bucket 310 stores a sufficient number of tokens, the corresponding output queue may accept a frame pointer corresponding to a data frame that awaits transmission by the switch 180. If the token bucket 310 stores an insufficient number of tokens, the data frame may be downgraded to a lower priority level or discarded.

The token buckets 310 may correspond to the high and low priority output queues of the output control queues 240. For example, the token buckets 310 may include high priority token buckets 312 and low priority token buckets 314. In alternative implementations consistent with the present invention, the number of priorities and, hence, the number of associated priority token buckets, may be greater than two.

The token buckets 310 may store tokens when instructed by the token bucket control logic 320 and may contain logic for controlling the acceptance of frame pointers by the corresponding output queues. In this way, the transmission of packets by the switch 180 may be controlled. The token buckets 310 may contain additional logic for adding a high priority token to the low priority token bucket 314 when the high priority token bucket 312 is full.

The token bucket control logic 320 may store tokens in the token buckets 310. FIG. 4 is a diagram of the token bucket control logic 320 according to an implementation consistent with the present invention. The token bucket control logic 320 may include a master counter 410 and multiple bucket counters 420. The master counter 410 and bucket counters 420 may be separately programmable (i.e., count rate and/or maximum count value) and possibly turned off via software.

The master counter 410 may include a programmable counter that acts as a master clock. The master counter 410 may increment to a programmable maximum count (max cnt) value and output a done signal that serves to increment the count value in the bucket counters 420. The master counter 410 may then reset the count value and resume counting.

The bucket counters 420 may include programmable counters that control the storage of tokens by the token buckets 310. The bucket counters 420 may correspond to the token buckets 310. For example, the bucket counters 420 may include high priority bucket counters 422 and low priority bucket counters 424. In alternative implementations consistent with the present invention, the number of priorities and, hence, the number of associated priority bucket counters, may be greater than two.

The bucket counters 420 may increment to programmable maximum count (max cnt2) values in response to the done pulses from the master counter 410. Each of the bucket counters 422 and 424 may have a different programmable maximum count value. When the bucket counters 420 reach the maximum count values, they output a token increment signal to the token buckets 310. The token increment signal causes the corresponding token bucket 310 to store an additional token.

FIG. 5 is an exemplary timing diagram of the operation of the token bucket control logic 320. As shown in FIG. 5, the master counter 410 counts to a programmable maximum count (max cnt) value. When the master counter 410 reaches the maximum count value, the master counter 410 outputs a done signal to each of the bucket counters 420. The done signal causes the bucket counters 420 to begin counting. Each of the bucket counters 420 counts to a programmable maximum count (max cnt2) value. The maximum count value may differ for each of the bucket counters 420. When a bucket counter 420 reaches the maximum count value, the bucket counter 420 outputs a token increment signal that causes a token to be added to the corresponding token bucket 310.

In some implementations consistent with the present invention, the bucket counters 420 automatically reset upon reaching the maximum count (max cnt2) value. In this case, the bucket counters 420 may count to the maximum count value multiple times prior to receiving each of the done signals from the master counter 410. As a result, the bucket counters 420 may output multiple token increment signals for each done signal from the master counter 410.

Exemplary Processing

FIG. 6 is a flowchart of exemplary processing for shaping traffic of the multiport switch 180 according to an implementation consistent with the present invention. Processing may begin with the multiport switch 180 receiving one or more packets. The receiver 205 may analyze the received packets to determine the number of bytes. The receiver 205 may then send a portion of the packets to the external memory 170 and a portion to the IRC 245. The IRC 245 may analyze the packet portions to generate forwarding descriptors for the packets. The token bucket logic 238 may receive the byte counts from the receiver 205 and the forwarding descriptors from the IRC 245 for particular packets. As described below, this information may be used by the token bucket logic 238 in determining whether to accept, downgrade the priority of, or discard the packets.

The master counter 410 begins counting to a programmable maximum count (max cnt) value. When the master counter 410 reaches the maximum count value, it generates a done signal [act 610]. The done signal causes each of the bucket counters 420 to begin counting to a programmable maximum count (max cnt2) value. As described above, the maximum count value may vary for the bucket counters 420 and may vary for the high and low priority bucket counters 422 and 424. When the bucket counters 420 reach the maximum count value, they generate a token increment signal [act 620]. The bucket counters 420 transmit the token increment signals to their corresponding token buckets 310. The token buckets 310 may then store a token in response to the token increment signals [act 630].

When the token bucket logic 238 receives the byte count and forwarding descriptor for a new packet [act 640], the token bucket logic 238 may shape traffic in the multiport switch 180 by deciding whether to accept, downgrade, or discard the packet [act 650]. For example, the token bucket logic 238 may be programmed to control the acceptance of frame pointers by one or more of the output queues. An output queue may be controlled to accept a frame pointer under the following conditions: (1) when the received byte count of the new packet is less than or equal to the number of tokens in the corresponding token bucket 310; or (2) when the received byte count of the new packet is less than or equal to the number of tokens in the corresponding token bucket 310 plus 1 and the token bucket 310 has received a token increment signal from the corresponding bucket counter 420. Otherwise, the priority level of the packet may be downgraded to a lower priority level or the packet may be discarded.

The programmability of the master counter 410 and bucket counters 420 and the acceptance or non-acceptance of the frame pointers by the output queues facilitate the control of packets through the switch 180.

Described has been systems and methods for shaping traffic in the multiport switch 180. Advantages of the present invention include maximizing the efficiency of and facilitating the provisioning of quality of service by the multiport switch 180.

Only the preferred embodiments of the invention and a few examples of its versatility are shown and described in the present disclosure. It is to be understood that the invention is capable of use in various other combinations and environments and is capable of modifications within the scope of the inventive concept as expressed herein. For example, while a series of acts has been described with regard to FIG. 6, the order of the acts may differ in other implementations consistent with the present invention.

Also, while a token has been described as corresponding to a byte of frame data, the token may correspond to an entire packet or another portion of a packet, greater or less than a byte, in other implementations consistent with the present invention.

Further, while the token bucket control logic 320 has been described as a group of counters, the token bucket control logic 320 may take other forms in other implementations consistent with the present invention. For example, the token bucket control logic 320 may use one or more clock generators to control the storage of tokens in the token buckets 310. 

1. A system for controlling traffic in a network device, comprising: a plurality of token buckets corresponding to a plurality of priority levels for each of a plurality of output ports of the network device and configured to store one or more tokens, each of the tokens corresponding to a byte of one or more received packets to be transmitted by the network device; and token bucket control logic configured to generate the tokens for the token buckets, the token bucket control logic including: a master counter configured to count to a first count value and generate a done signal when the count reaches the first count value, and a plurality of bucket counters corresponding to the token buckets and configured to receive the done signal, count to a second count value, and generate a token increment signal for storing a token in the corresponding token buckets when the count reaches the second count value.
 2. The system of claim 1, wherein at least one of a count rate or the first count value of the master counter is programmable.
 3. The system of claim 1, wherein at least one of a count rate or the second count value of the bucket counters is programmable.
 4. The system of claim 3, wherein at least one of the count rate or the second count value is separately programmable for each of the bucket counters.
 5. The system of claim 1, wherein each of the bucket counters is further configured to restart counting after the count reaches the second count value.
 6. The system of claim 1, wherein the token bucket logic is further configured to determine whether to accept one of the received packets for transmission by the network device.
 7. The system of claim 6, wherein the token bucket logic is configured to accept the received packet when a byte count for the received packet is less than or equal to a number of tokens in a corresponding one of the token buckets.
 8. The system of claim 6, wherein the token bucket logic is configured to accept the received packet when a byte count for the received packet is less than or equal to a number of tokens in a corresponding one of the token buckets plus one and the token increment signal has been generated by the corresponding bucket counter.
 9. The system of claim 6, wherein the token bucket logic is configured to one of downgrade a priority level of or discard the received packet when a byte count for the received packet is greater than a number of tokens in a corresponding one of the token buckets.
 10. The system of claim 1, wherein the token buckets include token buckets of different priority levels.
 11. A method for controlling traffic in a network device, comprising: counting to a first count value at a first count rate; outputting a done signal when the first count value is reached; counting to a second count value at a second count rate in response to the done signal; generating a token increment signal when the second count value is reached; storing a token in a token bucket in response to the token increment signal, the token bucket corresponding to a priority queue of an output port of the network device; and determining whether to accept a packet received by the network device based on a number of tokens stored in the token bucket.
 12. The method of claim 11, wherein at least one of the first count value or the first count rate is programmable.
 13. The method of claim 11, wherein at least one of the second count value or the second count rate is programmable.
 14. The method of claim 11, further comprising: restarting the counting to the second count value after the counting reaches the second count value.
 15. The method of claim 11, wherein the determining includes: accepting the received packet when a byte count for the received packet is less than or equal to the number of tokens in the token bucket.
 16. The method of claim 11, wherein the determining includes: accepting the received packet when a byte count for the received packet is less than or equal to the number of tokens in the token bucket plus one and the token increment signal has been generated.
 17. The method of claim 11, wherein the determining includes: discarding the received packet when a byte count for the received packet is greater than the number of tokens in the token bucket.
 18. The method of claim 11, wherein the determining includes: lowering a priority level of the received packet when a byte count for the received packet is greater than the number of tokens in the token bucket.
 19. A multiport network device, comprising: a receiver configured to receive a plurality of packets; a transmitter configured to transmit at least some of the received packets, the transmitter including a plurality of output ports; and token bucket logic configured to perform traffic shaping for the multiport network device, the token bucket logic including: a plurality of token buckets corresponding to multiple priority levels of each of the output ports and configured to store one or more tokens, each of the tokens corresponding to one or more of the received packets to be transmitted by one or more of the output ports, and token bucket control logic configured to generate the tokens for the token buckets, the token bucket control logic including: a master counter configured to count to a first count value and generate a done signal when the count reaches the first count value, and a plurality of bucket counters corresponding to the token buckets and configured to receive the done signal, count to a second count value, and generate a token increment signal for storing a token in the corresponding token buckets when the count reaches the second count value.
 20. The multiport network device of claim 19, wherein the token bucket logic is further configured to determine whether to accept, discard, or lower a priority level of one of the received packets based on a number of the tokens stored in a corresponding one of the token buckets. 